// 1. 定义 (路由) 组件
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import User from '../views/User.vue'
import Main from '../views/Main.vue'
import Mall from '../views/Mall.vue'
import Page1 from '../views/Page1.vue'
import Page2 from '../views/Page2.vue'
//2. 定义路由
Vue.use(VueRouter)

const routes = [
    //主路由
    {
        path: '/',
        component:Main,
        redirect:'/home', //重定向
        //子路由
        children: [
            { path: '/home',name:'home', component: Home },
            { path: '/user',name:'user', component: User },
            { path: '/mall',name:'mall', component: Mall },
            { path: '/page1',name:'page1', component: Page1 },
            { path: '/page2',name:'page2', component: Page2 }
        ]
    },
    
]
// 3. 创建 router 实例，然后传 `routes` 配置
const router = new VueRouter({
    routes // (缩写) 相当于 routes: routes
  })
  
// 4. 把路由对象暴露出去
export default router